export default {
    data() {
        return {
            tableData: [],
            order_id: 0,
            order_status:1,          //订单流程
            order_info:'',           //订单信息
            user_info:'',            //用户信息
            collect_goods:'',        //买家信息
            return_goods:'',         //返还信息
            order_amount:'',         //订单金额
            refund_evaluate:'',      //退款与评价
        }
    },

    //进入页面加载
    mounted: function() {
        var that = this;
        //在缓存中获取值
        that.user_name = sessionStorage.getItem("user_name");
        that.user_id = sessionStorage.getItem("user_id");
        that.token = sessionStorage.getItem("access-token");
        if((!that.token) || (!that.user_id) || (!that.user_name)) {
            that.$router.push('/login');
        }
        if(that.$route.query.order_id) {
            that.order_id = that.$route.query.order_id;
            that.detail();
        }
    },

    methods: {
        /**
         * 订单详情
         */
        detail: function() {
            var that = this;
            //请求登陆接口
            that.$http.post(that.adminApi.api_url + "/api/order/orderdetails", {
                token: that.token,
                order_id: that.order_id,
            }, {
                emulateJSON: true
            }).then(
                function(res) {
                    // 处理成功的结果
                    res.body.order_info.status_text = that.getOrderStatus(res.body.order_info);
                    that.order_info = res.body.order_info;
                    that.user_info = res.body.user_info;
                    that.collect_goods = res.body.collect_goods;
                    that.return_goods = res.body.return_goods;
                    that.order_amount = res.body.order_amount;
                    that.refund_evaluate = res.body.refund_evaluate;


                    //商品详情
                    that.tableData.push({
                        goods: "<div class='shop'><img src="+res.body.commodity_info.file+" class='shop_img'/><div class='shop_disc'><div style='display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3;overflow:hidden;'>"+res.body.commodity_info.goods_title+"</div> </div></div",
                        goods_sn:res.body.commodity_info.goods_sn,
                        grade: res.body.commodity_info.grade,
                        id: res.body.commodity_info.id,
                        exterior: res.body.commodity_info.shape,
                        color: res.body.commodity_info.color,
                        purpose: res.body.commodity_info.scene,
                    })
                },
                function() {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },


        /**
         * 跳转至详情
         */
        toGoodsDetail:function (e) {
            let that = this;
            that.$router.push({path: '/commodity/goods_detail', query: {goods_id: e}});
        },

        /**
         * 获取订单状态
         * @param res
         * @returns {string}
         */
        getOrderStatus: function(res) {
            var that= this;
            var status_text = "";
            switch(res.order_status) {
                case 1:
                    if ((res.is_pay === 3) && (res.is_cancel === 4)){
                        status_text = '正常-待付款'
                    }
                    if ((res.is_pay !== 3) && (res.is_deliver === 3) ){
                        status_text = '正常-支付成功';
                        that.order_status = 2;
                    }
                    if ((res.is_pay !== 3) && (res.is_deliver === 1) && (res.is_receipt === 3)) {
                        status_text = '正常-商品配送中';
                        that.order_status = 3;
                    }
                    if ((res.is_pay !== 3) && (res.is_receipt === 1) && (res.is_deliver === 1)&& (res.is_pickup === 3)) {
                        status_text = '正常-商品已签收';
                        that.order_status = 4;
                    }

                    if ((res.is_pay !== 3) && (res.is_pickup === 1) && (res.is_receipt === 1) && (res.is_deliver === 1)) {
                        status_text = '正常-商品取回中';
                        that.order_status = 5;
                    }

                    if ((res.is_pay !== 3) && (res.is_sign_back === 1) && (res.is_receipt === 1) && (res.is_deliver === 1)) {
                        status_text = '正常-商品已签还';
                        that.order_status = 6;
                    }
                    if ((res.is_pay !== 3) && (res.is_sign_back === 1) && (res.is_receipt === 1) && (res.is_deliver === 1)  && (res.check_accept_status === 1)) {
                        status_text = '正常-商品验收正常';
                        that.order_status = 7;
                    }
                    if ((res.is_pay !== 3) && (res.is_sign_back === 1) && (res.is_receipt === 1) && (res.is_deliver === 1)  && (res.check_accept_status === 2)) {
                        status_text = '正常-商品验收异常';
                        that.order_status = 7;
                    }
                    if ((res.is_pay !== 3) && (res.is_sign_back === 1) && (res.is_receipt === 1) && (res.is_deliver === 1)  && (res.is_check_accept === 1) && (res.is_refund ===1)) {
                        status_text = '正常-退款已汇出';
                        that.order_status = 8;
                    }
                    if ((res.is_over === 1)) {
                        status_text = '正常-订单已完成'
                    }
                    break;
                case 2:
                    if ((res.is_pay === 3) && (res.is_cancel === 2)) {
                        status_text = '正常-支付超时'
                    }
                    if ((res.is_pay !== 3) && (res.is_cancel === 3) && (res.is_deliver === 3) && (res.is_refund === 2)) {
                        status_text = '取消-支付成功'
                    }
                    if ((res.is_pay !== 3) && (res.is_refund === 3) && (res.is_cancel === 3)) {
                        status_text = '取消-支付成功'
                    }
                    if ((res.is_pay === 3) && (res.is_cancel === 3)) {
                        status_text = '取消-后台取消'
                    }

                    if ((res.is_pay !== 3) && (res.is_deliver === 1)) {
                        status_text = '取消-商品配送中'
                    }
                    if ((res.is_pay !== 3) && (res.is_refund === 1) && (res.is_cancel === 3)) {
                        status_text = '取消-退款已汇出'
                    }
                    if ((res.is_over === 1)) {
                        status_text = '取消-订单已完成'
                    }
                    break;
                default:
                    status_text = '订单已完成';
                    break;
            }
            return status_text;
        },

        /**
         * 跳转到用户详情
         */
        toUserDetail:function (e) {
            let that = this;
            that.$router.push({path: '/user/information', query: {member_id: e}});
        },

    }
}